package com.seveneight.baijiesteward.utils;

import android.text.TextUtils;

import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 * Created by user1 on 2018/3/30.
 */

public class StringFormat {

    public static String formatNumber(String str) {
        String num = "";
        NumberFormat nf = new DecimalFormat("0.00");
        Double d = Double.parseDouble(str);
        num = nf.format(d);
        return num;
    }

    public static String getCardNumber(String pNumber) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(pNumber) && pNumber.length() > 6) {
            for (int i = 0; i < pNumber.length(); i++) {
                char c = pNumber.charAt(i);
                if (i >= 6 && i <= pNumber.length() - 5) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }

    public static String getPhoneNumber(String pNumber) {
        StringBuilder sb = new StringBuilder();
        if (!TextUtils.isEmpty(pNumber) && pNumber.length() > 10) {
            for (int i = 0; i < pNumber.length(); i++) {
                char c = pNumber.charAt(i);
                if (i >= 3 && i <= pNumber.length() - 5) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
        }
        return sb.toString();
    }
}
